package com.lzq.train.batch.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.lzq.train.batch.feign.BusinessFeign;
import com.lzq.train.common.resp.CommonResp;
import jakarta.annotation.Resource;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.Date;

/**
 *
 * 生成每次车次数据
 *
 * 关闭并发执行
 */
@DisallowConcurrentExecution
public class DailyTrainJob implements Job {

    private final static Logger LOG = LoggerFactory.getLogger(DailyTrainJob.class);

    @Resource
    private BusinessFeign businessFeign;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 日志跟踪号
        MDC.put("LOG_ID", System.currentTimeMillis() + RandomUtil.randomString(3));

        LOG.info("生成15天后车次数据 开始");
        Date date = new Date();
        DateTime dateTime = DateUtil.offsetDay(date, 15);
        Date jdkDate = dateTime.toJdkDate();
        CommonResp<Object> resp = businessFeign.genDaily(jdkDate);
        LOG.info("生成15天后车次数据 结束：{}", resp);
    }
}
